from PIL import Image, ImageDraw, ImageFont


def create_image_with_link(
    ques, url, output_path=r"D:\Myprog\DDbot\File\URL.png", size=(800, 300)
):
    # 创建空白白色背景图片
    img = Image.new("RGB", size, color="white")
    draw = ImageDraw.Draw(img)
    font = ImageFont.truetype(r"C:/Windows/Fonts/simkai.ttf", 30)

    # 添加URL文本（可选视觉提示）
    draw.text((20, 50), f"[{ques}]", fill="blue", font=font)
    length = 45
    if len(url) < length:
        draw.text((20, 100), f"URL: {url}", fill="black", font=font)
    else:
        draw.text((20, 90), f"URL: {url[:length]}", fill="black", font=font)
        draw.text((20, 130), f"{" "*5}{url[length:]}", fill="black", font=font)

    # 保存图片并添加URL元数据
    img.save(output_path, format="PNG", quality=95)
    print(f"图片已生成并嵌入链接: {url}")


if __name__ == "__main__":
    ques = "发文登记"
    url = """【金山文档 | WPS云文档】 2024年度内河航运项目投资计划表
https://kdocs.cn/l/cbFHH0lGTvt7
【金山文档 | WPS云文档】 河南中豫航道有限公司资金中心月末统计表
https://kdocs.cn/l/cipEnvQ6AyvP"""

    create_image_with_link(ques, url)
